#! /bin/sh
# PCP QA Test No. 072
# pmlogger dumps core on this one?
#
# Copyright (c) 1995-2002 Silicon Graphics, Inc.  All Rights Reserved.
#

seq=`basename $0`
echo "QA output created by $seq"

# get standard filters
. ./common.product
. ./common.filter
. ./common.check

trap "rm -f $tmp $tmp.*; exit" 0 1 2 3 15

_filter()
{
    _filter_pmdumplog \
    | sed \
	-e 's/:.*//' \
	-e 's/[0-9][0-9]*\.[0-9][0-9]*\.[0-9][0-9]* (/PMID (/' \
	-e 's/TIMESTAMP/            /'
}

echo >$seq_full

# real QA test starts here
cat >$tmp.config <<End-of-File
# verbose
log mandatory on every 24 hours {
	hinv.physmem
	hinv.ncpu
	hinv.ndisk
	hinv.pagesize
}

mandatory on 50 msecs {
	kernel.percpu.cpu.user
	kernel.all.load
	disk.dev.total
	network.interface.in.bytes
	pmcd.pdu_in.fetch
	disk.dev.total # note repeated set of metrics
	mem.freemem
}
End-of-File

remote=`./getpmcdhosts -L -n 1 2>$tmp.out`
if [ -z "$remote" ]
then
    _notrun "`cat $tmp.out`"
    # NOTREACHED
fi

for host in `hostname` $remote
do
    echo
    echo "=== $host ===" >>$seq_full
    rm -f $tmp.0 $tmp.meta $tmp.index
    pmlogger -h $host -s 3 -c $tmp.config -l $tmp.out $tmp >$tmp.err 2>&1
    ( echo "pmlogger output:"; cat $tmp.err $tmp.out ) >>$seq_full
    cat $tmp.err $tmp.out | _filter_pmlogger_log

    pmdumplog -i $tmp 2>&1 >$tmp.out
    ( echo "pmdumplog -i:"; cat $tmp.out ) >>$seq_full

    numindom=`grep InDom: $tmp.out | wc -l | sed -e 's/  *//g'`
    if [ "X$numindom" != X5 ]
    then
	echo "for host $host, expected 5 InDom entries in the meta data, got ..."
	cat $tmp.out
    else
	echo "number of InDom entries is OK"
    fi

    echo "expect 2 sets of values for disks and 2 sets of values for networks ..."
    echo "pmdumplog:" >>$seq_full
    pmdumplog $tmp 2>&1 \
    | tee -a $seq_full \
    | grep -E 'disk\.|network\.' \
    | _filter \
    | LC_COLLATE=POSIX sort
done
